<?php
class mrekap extends CI_Model{

	function __construct()
	{
		parent::__construct();
	}
	
	function getList($sektor, $is_pengajuan){
		$this->db->select('month(tgl_terbit_police) as bulan,year(tgl_terbit_police) as tahun,tgl_terbit_police,count(id_pengaju) as total_pengaju,id_sektor');
		$this->db->from('t_data_police');
		$this->db->where('id_sektor', $sektor);
		$this->db->where('is_pengajuan', $is_pengajuan);
		$this->db->group_by('month(tgl_terbit_police)');
		$query = $this->db->get();
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function getDetail($month,$year,$sektor,$is_pengajuan)
	{
		$this->db->select('*,month(tgl_terbit_police) as bulan,year(tgl_terbit_police) as tahun');
		$this->db->from('t_pengaju');
		$this->db->join('t_data_police', 't_data_police.id_pengaju = t_pengaju.id_pengaju', 'left');
		$this->db->where('month(tgl_terbit_police)', $month);
		$this->db->where('year(tgl_terbit_police)', $year);
		$this->db->where('t_pengaju.id_sektor', $sektor);
		$this->db->where('t_pengaju.is_pengajuan', $is_pengajuan);
		$this->db->order_by('tgl_terbit_police','asc');
		$query = $this->db->get();
		return $query->result_array();
	}
	
	function getTglDetail($month,$year,$sektor,$is_pengajuan)
	{
		$this->db->select('tgl_terbit_police');
		$this->db->from('t_data_police');
		$this->db->where('month(tgl_terbit_police)', $month);
		$this->db->where('year(tgl_terbit_police)', $year);
		$this->db->where('id_sektor', $sektor);
		$this->db->where('is_pengajuan', $is_pengajuan);
		$this->db->group_by('tgl_terbit_police');
		$this->db->order_by('tgl_terbit_police','asc');

		$query = $this->db->get();
		return $query->result_array();
	}
}
?>